package org.acghub.mtdb.xmlgen;

import org.acghub.mtdb.common.Config;
import org.acghub.mtdb.common.Naming;

import java.util.ArrayList;
import java.util.List;

/**
 * @param <T>
 * @author zhouhe
 */
public abstract class Maker<T extends Naming> implements Makeable<T> {
    protected final List<Makeable> children = new ArrayList<>();
    private final T inner;
    private final Config config;

    public Maker(T inner, Config config) {
        this.inner = inner;
        this.config = config;
    }

    protected final <S extends Makeable> void addChild(S child) {
        this.children.add(child);
    }

    protected final <S extends Makeable> void addChildren(List<S> children) {
        this.children.addAll(children);
    }

    protected final void childrenMake() throws Exception {
        for (Makeable child : children) {
            child.make();
        }
    }

    @Override
    public T inner() {
        return inner;
    }

    @Override
    public Config config() {
        return config;
    }

}
